package com.odianyun.hello.web.controller;

import com.odianyun.hello.model.PO.Article;
import com.odianyun.hello.model.PO.ArticleExtends.CommentInfo;
import com.odianyun.hello.model.PO.ArticleExtends.LikeInfo;
import com.odianyun.hello.service.IArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "文章管理")
@RequestMapping("article")
public class ArticleController {


    @Resource
    private IArticleService articleService;

    @ApiOperation("添加文章")
    @PostMapping("addArticle")
    public String addArticle(@RequestBody Article article){
        return articleService.addArticle(article);
    }

    @ApiOperation("根据模糊标题查询文章")
    @PostMapping("findArticleByTitleRegex")
    public List<Article> findArticleByTitleRegex(String title){
        return articleService.findArticleByTitleRegex(title);
    }

    @ApiOperation("根据id删除文章")
    @PostMapping("deleteArticleById")
    public void deleteArticleById(String id){
        articleService.deleteArticleById(id);
    }

    @ApiOperation("根据标题浏览文章")
    @PostMapping("getArticleByTitle")
    public List<Article> getArticleByTitle(String title){
        List<Article> articles = articleService.getArticleByTitle(title);
        return articles;
    }

    @ApiOperation("添加评论")
    @PostMapping("addComment")
    public void addComment(String id , @RequestBody CommentInfo commentInfos){
        articleService.addComment(id,commentInfos);
    }

    @ApiOperation("删除评论")
    @PostMapping("deleteComment")
    public void deleteComment(String title , String id){
        articleService.deleteComment(title,id);
    }

    @ApiOperation("点赞文章（添加点赞信息）")
    @PostMapping("addLike")
    public String addLike(String id , @RequestBody LikeInfo likeInfos){
        articleService.addLike(id,likeInfos);
        return "success";
    }

    @ApiOperation("删除点赞")
    @PostMapping("deleteLike")
    public void deleteLike(String title , String id){
        articleService.deleteLike(title,id);
    }

}
